]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
polkit: return error when authentication dialog is dismissed
authorDavid Zeuthen <davidz@redhat.com>
Tue, 22 Feb 2011 21:54:08 +0000 (16:54 -0500)
committerDavid Zeuthen <davidz@redhat.com>
Wed, 23 Feb 2011 16:02:46 +0000 (11:02 -0500)
This allows PolicyKit applications to disambiguate between when the
authentication dialog is dismissed versus when authentication fails
(e.g. the wrong password has been entered).

See https://bugs.freedesktop.org/show_bug.cgi?id=30653 for more
information.

Signed-off-by: David Zeuthen <davidz@redhat.com>
js/ui/polkitAuthenticationAgent.js
src/shell-polkit-authentication-agent.c
src/shell-polkit-authentication-agent.h

index 294c58df988dee13be3c244d13c67e58247b0e56..cc5e5913f5a1620cb9308b1e187ce71bb9b9bef1 100644 (file)
@@ -192,10 +192,10 @@ AuthenticationDialog.prototype = {
                      }));
     },
 
-    _emitDone: function(keepVisible) {
+    _emitDone: function(keepVisible, dismissed) {
         if (!this._doneEmitted) {
             this._doneEmitted = true;
-            this.emit('done', keepVisible);
+            this.emit('done', keepVisible, dismissed);
         }
     },
 
@@ -214,7 +214,7 @@ AuthenticationDialog.prototype = {
 
     _onSessionCompleted: function(session, gainedAuthorization) {
         this._passwordBox.hide();
-        this._emitDone(!gainedAuthorization);
+        this._emitDone(!gainedAuthorization, false);
     },
 
     _onSessionRequest: function(session, request, echo_on) {
@@ -270,7 +270,7 @@ AuthenticationDialog.prototype = {
 
     cancel: function() {
         this.close(global.get_current_time());
-        this._emitDone(false);
+        this._emitDone(false, true);
     },
 
 };
@@ -302,30 +302,30 @@ AuthenticationAgent.prototype = {
             log('polkitAuthenticationAgent: Failed to show modal dialog');
             this._currentDialog.destroySession();
             this._currentDialog = null;
-            this._native.complete()
+            this._native.complete(false)
         } else {
             this._currentDialog.connect('done', Lang.bind(this, this._onDialogDone));
         }
     },
 
     _onCancel: function(nativeAgent) {
-        this._completeRequest(false);
+        this._completeRequest(false, false);
     },
 
-    _onDialogDone: function(dialog, keepVisible) {
-        this._completeRequest(keepVisible);
+    _onDialogDone: function(dialog, keepVisible, dismissed) {
+        this._completeRequest(keepVisible, dismissed);
     },
 
-    _reallyCompleteRequest: function() {
+    _reallyCompleteRequest: function(dismissed) {
         this._currentDialog.close();
         this._currentDialog.destroySession();
         this._currentDialog = null;
         this._isCompleting = false;
 
-        this._native.complete()
+        this._native.complete(dismissed)
     },
 
-    _completeRequest: function(keepVisible) {
+    _completeRequest: function(keepVisible, wasDismissed) {
         if (this._isCompleting)
             return;
 
@@ -337,10 +337,10 @@ AuthenticationAgent.prototype = {
             Mainloop.timeout_add(2000,
                                  Lang.bind(this,
                                            function() {
-                                               this._reallyCompleteRequest();
+                                               this._reallyCompleteRequest(wasDismissed);
                                            }));
         } else {
-            this._reallyCompleteRequest();
+            this._reallyCompleteRequest(wasDismissed);
         }
     }
 }
index 2ac120dfe2359f3d1f7a3cb755c5a2ae0da69d0d..a84d8b6fe424b3ec4c01ea6893c38c9336bbd27e 100644 (file)
@@ -16,6 +16,8 @@
 #include <polkitagent/polkitagent.h>
 #include "shell-polkit-authentication-agent.h"
 
+#include <glib/gi18n.h>
+
 /* uncomment for useful debug output */
 /* #define SHOW_DEBUG */
 
@@ -282,7 +284,8 @@ auth_request_initiate (AuthRequest *request)
   g_strfreev (user_names);
 }
 
-static void auth_request_complete (AuthRequest *request);
+static void auth_request_complete (AuthRequest *request,
+                                   gboolean     dismissed);
 
 static gboolean
 handle_cancelled_in_idle (gpointer user_data)
@@ -298,7 +301,7 @@ handle_cancelled_in_idle (gpointer user_data)
     }
   else
     {
-      auth_request_complete (request);
+      auth_request_complete (request, FALSE);
     }
 
   return FALSE;
@@ -319,10 +322,17 @@ on_request_cancelled (GCancellable *cancellable,
 static void maybe_process_next_request (ShellPolkitAuthenticationAgent *agent);
 
 static void
-auth_request_complete (AuthRequest *request)
+auth_request_complete (AuthRequest *request,
+                       gboolean     dismissed)
 {
   ShellPolkitAuthenticationAgent *agent = request->agent;
 
+  if (dismissed)
+    g_simple_async_result_set_error (request->simple,
+                                     POLKIT_ERROR,
+                                     POLKIT_ERROR_CANCELLED,
+                                     _("Authentation dialog was dismissed by the user"));
+
   if (agent->current_request == request)
     {
       print_debug ("COMPLETING CURRENT %s cookie %s", request->action_id, request->cookie);
@@ -415,10 +425,11 @@ initiate_authentication_finish (PolkitAgentListener  *listener,
 }
 
 void
-shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent)
+shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent,
+                                            gboolean                        dismissed)
 {
   g_return_if_fail (SHELL_IS_POLKIT_AUTHENTICATION_AGENT (agent));
   g_return_if_fail (agent->current_request != NULL);
 
-  auth_request_complete (agent->current_request);
+  auth_request_complete (agent->current_request, dismissed);
 }
index 9dbd215d87f70e3ed950440fea8b94fda53b2d29..a8758ae92ff47906a4f6a85a6effa53ee1422b9c 100644 (file)
@@ -25,7 +25,8 @@ typedef struct _ShellPolkitAuthenticationAgentClass ShellPolkitAuthenticationAge
 
 GType                           shell_polkit_authentication_agent_get_type (void) G_GNUC_CONST;
 ShellPolkitAuthenticationAgent *shell_polkit_authentication_agent_new      (void);
-void                            shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent);
+void                            shell_polkit_authentication_agent_complete (ShellPolkitAuthenticationAgent *agent,
+                                                                            gboolean                        dismissed);
 
 G_END_DECLS